package cn.edu.zafu.bigdata.fyc;

public abstract class Shape {
    // 抽象方法，用于计算形状的面积
    public abstract double area();

    // 抽象方法，用于计算形状的周长
    public abstract double perimeter();

    // final方法，用于打印形状的类型、面积和周长
    public final void display() {
        System.out.println("Shape Type: " + this.getClass().getSimpleName());
        System.out.println("Area: " + area());
        System.out.println("Perimeter: " + perimeter());
    }
}

// Circle 类，继承自 Shape
class Circle extends Shape {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    // 实现 area() 方法
    @Override
    public double area() {
        return Math.PI * radius * radius;
    }

    // 实现 perimeter() 方法
    @Override
    public double perimeter() {
        return 2 * Math.PI * radius;
    }
}

// Rectangle 类，继承自 Shape
class Rectangle extends Shape {
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    // 实现 area() 方法
    @Override
    public double area() {
        return length * width;
    }

    // 实现 perimeter() 方法
    @Override
    public double perimeter() {
        return 2 * (length + width);
    }
}